package com.gxuwz.weather.adapter;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
import androidx.viewpager2.adapter.FragmentStateAdapter;

import com.gxuwz.weather.fragment.WeatherFragment;
import com.gxuwz.weather.model.Weathernow;

import java.util.List;

public class WeatherPagerAdapter extends FragmentStateAdapter {
    private List<Weathernow> weatherList;

    public WeatherPagerAdapter(@NonNull FragmentActivity fragmentActivity, List<Weathernow> weatherList) {
        super(fragmentActivity);
        this.weatherList = weatherList;
    }

    @NonNull
    @Override
    public Fragment createFragment(int position) {
        // 返回一个 WeatherFragment 对象，并传递 Weathernow 数据
        return WeatherFragment.newInstance(weatherList.get(position));
    }

    @Override
    public int getItemCount() {
        // 返回页面的数量
        return weatherList.size();
    }
}
